package com.jxsd.edu.cn.struts2.daoImpl;

import java.util.List;

import com.jxsd.edu.cn.struts2.dao.ReplyDao;
import com.jxsd.edu.cn.struts2.models.Reply;
import com.jxsd.edu.cn.tools.ResultBean;
import com.jxsd.edu.cn.tools.ResultList;
import com.jxsd.edu.cn.tools.StringTool;
import com.jxsd.edu.cn.tools.Template;

public class ReplyDaoImpl   implements  ReplyDao 
{

	@Override
	public void addReply(Reply reply) {
		String  sql="insert  into  Reply(TopicID,replyTime,replyContent,userID,forReplyId) values(?,?,?,?,?)";
		Object[] params={reply.getTopicID(),StringTool.getCurDate(),reply.getReplyContent(),reply.getUserID(),reply.getForReplyId()};
		Template  template=new  Template();
		template.update(sql, params);
	}

	@Override
	public void deleteReply(String replyId) {
		String  sql="delete  from  reply  where  replyId=?";
		Object[] params={replyId};
		Template  template=new  Template();
		template.update(sql, params);
	}

	@Override
	public Reply getReply(String replyId) {
		String  sql="select  ReplyID,topicID,replyTime,replyContent," +
				"userID,nickName,Image,forReplyId  from  replyview  where  replyId=?";
		Object[] params={replyId};
		Reply  reply=null;
		ResultBean<Reply>  bean=new  ResultBean<Reply>();
		try {
			reply=bean.handler(sql, params, Reply.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return reply;
	}

	@Override
	public List<Reply> getReplies(int topicId) {
		String  sql="select  ReplyID,topicID,replyTime,replyContent," +
				"userID,nickName,Image,forReplyId  from  replyview  where  topicId=?";
		Object[] params={topicId};
		List<Reply>  list=null;
		ResultList<Reply>  bean=new  ResultList<Reply>();
		try {
			list=bean.handler(sql, params, Reply.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return    list;
	}
   
}
